﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Framework;

namespace MessengerBot.Tests
{
    [TestFixture]
    public class BotTests
    {
        [TestCase("")]
        [TestCase((string)null)]
        [TestCase(" \t\n\r ")]
        public void Constructor_ConfigurationWithNullOrEmptyUserName_ThrowsInvalidOperationException(string input)
        {
            var configuration = new BotConfiguration();
            configuration.Username = input;
            configuration.Password = "password";

            Assert.Throws<InvalidOperationException>(() => new Bot(configuration));
        }

        [TestCase("")]
        [TestCase((string)null)]
        [TestCase(" \t\n\r ")]
        public void Constructor_ConfigurationWithNullOrEmptyPassword_ThrowsInvalidOperationException(string input)
        {
            var configuration = new BotConfiguration();
            configuration.Username = "username";
            configuration.Password = input;

            Assert.Throws<InvalidOperationException>(() => new Bot(configuration));
        }

        [TestCase("u", "p")]
        [TestCase("username", "password")]
        public void Constructor_AssignsConfigurationToProperty(string username, string password)
        {
            var configuration = new BotConfiguration();
            configuration.Username = username;
            configuration.Password = password;

            var bot = new Bot(configuration);

            Assert.That(bot.Configuration.Username, Is.EqualTo(configuration.Username));
            Assert.That(bot.Configuration.Password, Is.EqualTo(configuration.Password));
        }

        [Test]
        public void Constructor_FreezesConfiguration()
        {
            var configuration = new BotConfiguration();
            configuration.Username = "username";
            configuration.Password = "password";

            new Bot(configuration);

            Assert.That(configuration.IsFrozen, Is.True);
        }

        [Test]
        public void Constructor_NullConfiguration_ThrowsArgumentNullException()
        {
            BotConfiguration configuration = null;

            Assert.Throws<ArgumentNullException>(() => new Bot(configuration));
        }
    }
}